package com.example.showlocation.adapter;

import static android.view.View.VISIBLE;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.showlocation.R;

public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ItemViewHolder> {
    String[][] myDataset;
    CompoundButton.OnCheckedChangeListener onCheckedChangeListener;
    public ItemAdapter(String[][] myDataset, CompoundButton.OnCheckedChangeListener onCheckedChangeListener){
       this. myDataset=myDataset;
       this.onCheckedChangeListener=onCheckedChangeListener;
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // create a new view
        View  adapterLayout = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item, parent, false);
        return new ItemViewHolder(adapterLayout);
    }

    @Override
    public void onBindViewHolder(@NonNull ItemAdapter.ItemViewHolder holder, int position) {
        holder.textView11.setText(myDataset[position][0]);
        if ( position== 0) {
            holder.radioButton.setVisibility( VISIBLE);
            holder.radioButton.setOnCheckedChangeListener(onCheckedChangeListener);
        } else {
            holder.textView12.setText(myDataset[position][1]);
            holder.textView13.setText(myDataset[position][2]+"meters") ;
        }
        if(position>1){
            Log.d("ItemAdapter:",myDataset[position][0]);
            Log.d("ItemAdapter:",myDataset[position][1]);
            Log.d("ItemAdapter:",myDataset[position][2]);
        }
    }
    @Override
    public int getItemCount() {
        return myDataset.length;
    }
   public class ItemViewHolder extends RecyclerView.ViewHolder {
        public ItemViewHolder(@NonNull View itemView) {
            super(itemView);
        }
       TextView textView11 = itemView.findViewById(R.id.textView11);
       TextView textView12 = itemView.findViewById(R.id.textView12);
       TextView textView13 = itemView.findViewById(R.id.textView13);
       RadioButton radioButton= itemView.findViewById(R.id.radioButton);
    }
}
